package daos;

import org.hibernate.Session;
import org.hibernate.Transaction;

import utilHibernate.HibernateUtil;



public class DaoFactory {
	
	private final Session session;
	private Transaction transaction;
	
	public DaoFactory() {
		session = HibernateUtil.getSession();
	}
	
	public void beginTransaction() {
		this.transaction = this.session.beginTransaction();
	}
		
	public void commit() {
		this.transaction.commit();
		this.transaction = null;
	}
	
	public boolean hasTransaction() {
		return this.transaction != null;
	}
	
	public void flush() {
		this.session.flush();
	}
	
	public void clear(){
		this.session.clear();
	}
	
	public void anula(){
		this.transaction = null;
	}
	
	public void rollback() {
		this.transaction.rollback();
		this.transaction = null;
	}
	
	public void close() {
		this.session.close();
	}
	
	public <T> Dao<T> getClasse(Class<T> ClasseObjeto){
		return new Dao<T>(this.session, ClasseObjeto);
	}

}
